package com.jiyongjun.component.config;

import com.aliyun.openservices.log.common.IndexKey;
import com.jiyongjun.component.core.model.*;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;

/**
 * <h2>日志配置-使用switch</h2>
 * <h3>描述：</h3>
 *
 * @author yongjun.jyj
 * @since 2022/7/14 17:36
 */
public class LogSwitch {
    /** 不记录响应结果的api集合 */
    public static Set<String> LOG_RESULT_API_BLACKLIST = new HashSet<>();
    /** 属于业务异常的异常码集合 */
    public static Set<String> BIZ_EXCEPTION_CODES = new HashSet<>();
    /** 日志库索引 */
    public static Map<String, IndexKey> SLS_LOG_INDEXS = new HashMap<>();

    static {
        Field[] fields = BaseLogContext.class.getDeclaredFields();
        ArrayList<Field> fieldList = new ArrayList<>(Arrays.asList(fields));
        fieldList.addAll(Arrays.asList(DefaultLogContext.class.getDeclaredFields()));
        fieldList.addAll(Arrays.asList(MethodLogContext.class.getDeclaredFields()));
        fieldList.addAll(Arrays.asList(DubboLogContext.class.getDeclaredFields()));
        fieldList.addAll(Arrays.asList(MqLogContext.class.getDeclaredFields()));

        fieldList.stream()
                .filter(field -> !Modifier.isTransient(field.getModifiers()) && !Modifier.isStatic(field.getModifiers()) && !"extInfoMap".equals(field.getName()))
                .forEach(field -> {

                });
    }

    /** 异常监控报表 */
    public static String SLS_EXCEPTION_DASHBOARD = "{\"dashboardName\":\"dashboard-medical-channel-exception_online\",\"description\":\"\",\"displayName\":\"medical-channel接口报表(online)\",\"attribute\":{},\"charts\":[{\"title\":\"dashboard-medical-channel-exception_online-chat1\",\"type\":\"tablepro\",\"search\":{\"chartQueries\":[{\"datasource\":\"logstore\",\"displayName\":\"当前查询\",\"logstore\":\"medical-channel\",\"name\":\"A\",\"project\":\"alihealth-medical\",\"query\":\"(env: pre) | SELECT \\n\\tapiName, \\n\\tarbitrary(apiDesc) \\\"接口描述\\\",\\n\\tarbitrary(apiType) \\\"接口类型\\\",\\n\\tCOUNT(*) pv,  \\n\\tcast(truncate(avg(elapsedTime)) as bigint) \\\"rt(ms)\\\", \\n\\tapprox_percentile(elapsedTime,0.95) \\\"rt(95%)\\\", \\n\\tapprox_percentile(elapsedTime,0.97) \\\"rt(97%)\\\", \\n\\tapprox_percentile(elapsedTime,0.99) \\\"rt(99%)\\\", \\n\\tmax(elapsedTime) \\\"最大rt\\\",  \\n\\tmax_by(eagleEyeId, elapsedTime) \\\"最大耗时鹰眼id\\\"\\n    GROUP BY\\n      apiName\\n    ORDER BY\\n      \\\"rt(ms)\\\" DESC\",\"tokenQuery\":\"(env: online) | SELECT \\n\\tapiName, \\n\\tarbitrary(apiDesc) \\\"接口描述\\\",\\n\\tarbitrary(apiType) \\\"接口类型\\\",\\n\\tCOUNT(*) pv,  \\n\\tcast(truncate(avg(elapsedTime)) as bigint) \\\"rt(ms)\\\", \\n\\tapprox_percentile(elapsedTime,0.95) \\\"rt(95%)\\\", \\n\\tapprox_percentile(elapsedTime,0.97) \\\"rt(97%)\\\", \\n\\tapprox_percentile(elapsedTime,0.99) \\\"rt(99%)\\\", \\n\\tmax(elapsedTime) \\\"最大rt\\\",  \\n\\tmax_by(eagleEyeId, elapsedTime) \\\"最大耗时鹰眼id\\\"\\n    GROUP BY\\n      apiName\\n    ORDER BY\\n      \\\"rt(ms)\\\" DESC\"}],\"end\":\"now\",\"logstore\":\"medical-channel\",\"query\":\"@\",\"start\":\"-86400s\",\"topic\":\"\"},\"display\":{\"actionOptions\":[{\"events\":[{\"event\":\"logstore\",\"values\":{\"dashboardName\":\"dashboard-medical-channel-exception_online\",\"filterInherit\":true,\"logstoreName\":\"medical-channel\",\"name\":\"打开日志库\",\"project\":\"alihealth-medical\",\"searchFilter\":\"env: online and eagleEyeId: ${最大耗时鹰眼id}\",\"timeRange\":-1}}],\"name\":\"最大rt\",\"queryName\":\"A\"},{\"events\":[{\"event\":\"logstore\",\"values\":{\"dashboardName\":\"dashboard-medical-channel-exception_online\",\"filterInherit\":true,\"logstoreName\":\"medical-channel\",\"name\":\"打开日志库\",\"project\":\"alihealth-medical\",\"searchFilter\":\"env: online and  apiName: ${apiName}\",\"timeRange\":-1}}],\"name\":\"apiName\",\"newAdd\":true,\"queryName\":\"A\"}],\"basicOptions\":{\"displayName\":\"性能报表\",\"fixedTime\":false,\"showBackground\":false,\"showBorder\":false,\"showTime\":true,\"showTitle\":true},\"columnOptions\":{\"cellMode\":\"none\",\"closeSearch\":false,\"closeSort\":false,\"columnAlign\":\"left\",\"columnMinWidth\":100,\"columnWidth\":164,\"fontSize\":12},\"displayName\":\"\",\"fieldOptions\":[{\"name\":\"apiName\",\"newAdd\":true,\"overrides\":[{\"optionKeys\":[\"columnOptions\",\"columnMinWidth\"],\"value\":300}],\"queryName\":\"A\"}],\"height\":6.931818,\"queryOptionMap\":{\"A\":{\"closedKeys\":[\"最大耗时鹰眼id\"]}},\"showBackground\":true,\"showBorder\":true,\"showTitle\":true,\"standardOption\":{\"decimals\":2,\"format\":\"none\",\"unit\":\"none\"},\"tableOptions\":{\"pageSize\":20,\"rowHeight\":36,\"showGaugeTitle\":true,\"showHeader\":true,\"showMode\":\"pagination\",\"showTotal\":true,\"transparentBackground\":false},\"valueMappingOption\":[],\"version\":2,\"width\":10.08,\"xPos\":-0.05,\"yPos\":6.4204545,\"zIndex\":10},\"action\":{}},{\"title\":\"dashboard-medical-channel-exception_online-chat2\",\"type\":\"tablepro\",\"search\":{\"chartQueries\":[{\"datasource\":\"logstore\",\"displayName\":\"A\",\"logstore\":\"medical-channel\",\"name\":\"A\",\"project\":\"alihealth-medical\",\"query\":\"(env: online AND success: False not FAIL_BIZ_SESSION_INVALID not 黑盒测试_答疑群_21912598)| \\nSELECT resultType \\\"异常类型\\\", \\n\\tarbitrary(errorCode) errorCode, \\n\\tarbitrary(apiType) \\\"接口类型\\\", \\n\\terrorMsg, \\n\\tcount(*) \\\"数量\\\" \\nGROUP BY \\\"异常类型\\\", errorMsg \\norder by \\\"异常类型\\\" DESC, \\\"数量\\\" DESC  \\nlimit 1000\",\"tokenQuery\":\"(env: online AND success: False not FAIL_BIZ_SESSION_INVALID not 黑盒测试_答疑群_21912598)| \\nSELECT resultType \\\"异常类型\\\", \\n\\tarbitrary(errorCode) errorCode, \\n\\tarbitrary(apiType) \\\"接口类型\\\", \\n\\terrorMsg, \\n\\tcount(*) \\\"数量\\\" \\nGROUP BY \\\"异常类型\\\", errorMsg \\norder by \\\"异常类型\\\" DESC, \\\"数量\\\" DESC  \\nlimit 1000\"}],\"end\":\"now\",\"logstore\":\"medical-channel\",\"query\":\"@\",\"start\":\"-86400s\",\"topic\":\"\"},\"display\":{\"actionOptions\":[{\"events\":[{\"event\":\"logstore\",\"values\":{\"filterInherit\":true,\"logstoreName\":\"medical-channel\",\"name\":\"打开日志库\",\"project\":\"alihealth-medical\",\"searchFilter\":\"env: online AND success: False AND resultType:${异常类型} and errorCode:${errorCode}  and apiType: ${接口类型} and errorMsg:\\\"${errorMsg} \\\"  \",\"timeRange\":-1}}],\"name\":\"数量\",\"queryName\":\"A\"}],\"basicOptions\":{\"displayName\":\"错误码报表\",\"fixedTime\":false,\"showBackground\":false,\"showBorder\":false,\"showTime\":true,\"showTitle\":true},\"columnOptions\":{\"cellMode\":\"none\",\"closeSearch\":false,\"closeSort\":false,\"columnAlign\":\"left\",\"columnMinWidth\":100,\"columnWidth\":75,\"fontSize\":12},\"displayName\":\"\",\"fieldOptions\":[{\"name\":\"errorCode\",\"overrides\":[{\"optionKeys\":[\"columnOptions\",\"columnWidth\"],\"value\":230},{\"optionKeys\":[\"columnOptions\",\"fontSize\"],\"value\":13}],\"queryName\":\"A\"},{\"name\":\"数量\",\"overrides\":[{\"optionKeys\":[\"standardOption\",\"colorSchame\"],\"value\":{\"color\":\"#0070cc\",\"schema\":\"threshold\"}},{\"optionKeys\":[\"thresholds\"],\"value\":[{\"color\":\"rgb(115, 191, 105)\",\"rule\":\">\",\"value\":0},{\"color\":\"rgb(227, 211, 84)\",\"rule\":\">\",\"value\":5},{\"color\":\"rgb(247, 163, 91)\",\"rule\":\">\",\"value\":20},{\"color\":\"rgb(255, 0, 0)\",\"rule\":\">\",\"value\":50}]},{\"optionKeys\":[\"columnOptions\",\"cellMode\"],\"value\":\"text\"},{\"optionKeys\":[\"columnOptions\",\"fontSize\"],\"value\":14}],\"queryName\":\"A\"},{\"name\":\"errorMsg\",\"overrides\":[{\"optionKeys\":[\"columnOptions\",\"columnWidth\"],\"value\":190},{\"optionKeys\":[\"columnOptions\",\"fontSize\"],\"value\":14}],\"queryName\":\"A\"},{\"name\":\"异常类型\",\"overrides\":[{\"optionKeys\":[\"columnOptions\",\"columnWidth\"],\"value\":115}],\"queryName\":\"A\"},{\"name\":\"接口类型\",\"overrides\":[{\"optionKeys\":[\"columnOptions\",\"columnWidth\"],\"value\":120}],\"queryName\":\"A\"}],\"height\":6.4772725,\"queryOptionMap\":{\"A\":{}},\"showTitle\":true,\"standardOption\":{\"decimals\":2,\"format\":\"none\",\"unit\":\"none\"},\"tableOptions\":{\"pageSize\":20,\"rowHeight\":36,\"showGaugeTitle\":true,\"showHeader\":true,\"showMode\":\"pagination\",\"showTotal\":true,\"transparentBackground\":false},\"valueMappingOption\":[],\"version\":2,\"width\":5.08,\"xPos\":4.95,\"yPos\":-0.056818184,\"zIndex\":10},\"action\":{}},{\"title\":\"dashboard-medical-channel-exception_online-chat3\",\"type\":\"tablepro\",\"search\":{\"chartQueries\":[{\"datasource\":\"logstore\",\"displayName\":\"A\",\"logstore\":\"medical-channel\",\"name\":\"A\",\"project\":\"alihealth-medical\",\"query\":\"(* AND env: online not errorCode: FAIL_BIZ_SESSION_INVALID not 黑盒测试_答疑群_21912598)| \\nSELECT \\n\\tapiName \\\"接口名称\\\", \\n\\tarbitrary(apiDesc) \\\"接口描述\\\",\\n\\tarbitrary(apiType) \\\"接口类型\\\",\\n\\tCOUNT(*) pv,\\n\\tCOUNT(DISTINCT tbUserId) uv,\\n\\tconcat(cast(round(count_if(success='true') / (COUNT(*) * 1.0) * 100, 2) as varchar), '%') \\\"成功率\\\",\\n\\tcount_if(resultType = 'biz_exception') \\\"业务异常\\\",\\n\\tcount_if(resultType = 'service_exception') \\\"服务异常\\\"\\nGROUP BY\\n  apiName\\norder by\\n  \\\"服务异常\\\" DESC\\nlimit 100 \",\"tokenQuery\":\"(* AND env: online not errorCode: FAIL_BIZ_SESSION_INVALID not 黑盒测试_答疑群_21912598)| \\nSELECT \\n\\tapiName \\\"接口名称\\\", \\n\\tarbitrary(apiDesc) \\\"接口描述\\\",\\n\\tarbitrary(apiType) \\\"接口类型\\\",\\n\\tCOUNT(*) pv,\\n\\tCOUNT(DISTINCT tbUserId) uv,\\n\\tconcat(cast(round(count_if(success='true') / (COUNT(*) * 1.0) * 100, 2) as varchar), '%') \\\"成功率\\\",\\n\\tcount_if(resultType = 'biz_exception') \\\"业务异常\\\",\\n\\tcount_if(resultType = 'service_exception') \\\"服务异常\\\"\\nGROUP BY\\n  apiName\\norder by\\n  \\\"服务异常\\\" DESC\\nlimit 100 \"}],\"end\":\"now\",\"logstore\":\"medical-channel\",\"query\":\"@\",\"start\":\"-86400s\",\"topic\":\"\"},\"display\":{\"actionOptions\":[{\"events\":[{\"event\":\"dashboard\",\"values\":{\"dashboardName\":\"dashboard-medical-channel-exception_online\",\"filterInherit\":true,\"logstoreName\":\"medical-channel\",\"name\":\"打开仪表盘\",\"project\":\"alihealth-medical\",\"searchFilter\":\"env: online and apiName:${接口名称}\",\"searchStaticToken\":[],\"searchToken\":[],\"timeRange\":-1,\"tokenInherit\":true}}],\"name\":\"接口名称\",\"queryName\":\"A\"},{\"events\":[{\"event\":\"logstore\",\"values\":{\"dashboardName\":\"dashboard-medical-channel-exception_online\",\"filterInherit\":false,\"logstoreName\":\"medical-channel\",\"name\":\"打开日志库\",\"project\":\"alihealth-medical\",\"searchFilter\":\"env: online and apiName:${接口名称} and resultType:biz_exception\",\"timeRange\":-1}}],\"name\":\"业务异常\",\"newAdd\":true,\"queryName\":\"A\"},{\"events\":[{\"event\":\"logstore\",\"values\":{\"dashboardName\":\"dashboard-medical-channel-exception_online\",\"filterInherit\":false,\"logstoreName\":\"medical-channel\",\"name\":\"打开日志库\",\"project\":\"alihealth-medical\",\"searchFilter\":\"env: online and apiName:${接口名称} and resultType:service_exception\",\"timeRange\":-1}}],\"name\":\"服务异常\",\"newAdd\":true,\"queryName\":\"A\"}],\"basicOptions\":{\"displayName\":\"接口异常报表\",\"fixedTime\":false,\"showBackground\":false,\"showBorder\":false,\"showTime\":true,\"showTitle\":true},\"columnOptions\":{\"cellMode\":\"none\",\"closeSearch\":false,\"closeSort\":false,\"columnAlign\":\"left\",\"columnMinWidth\":100,\"columnWidth\":60,\"fontSize\":12},\"displayName\":\"\",\"fieldOptions\":[{\"name\":\"接口名称\",\"overrides\":[{\"optionKeys\":[\"columnOptions\",\"columnWidth\"],\"value\":200}],\"queryName\":\"A\"},{\"name\":\"接口描述\",\"overrides\":[{\"optionKeys\":[\"columnOptions\",\"columnWidth\"],\"value\":120},{\"optionKeys\":[\"columnOptions\",\"fontSize\"],\"value\":14}],\"queryName\":\"A\"},{\"name\":\"接口类型\",\"overrides\":[{\"optionKeys\":[\"columnOptions\",\"columnWidth\"],\"value\":115}],\"queryName\":\"A\"},{\"name\":\"成功率\",\"overrides\":[{\"optionKeys\":[\"columnOptions\",\"columnWidth\"],\"value\":60}],\"queryName\":\"A\"},{\"name\":\"业务异常\",\"overrides\":[{\"optionKeys\":[\"thresholds\"],\"value\":[{\"color\":\"rgb(115, 191, 105)\",\"rule\":\">\",\"value\":0},{\"color\":\"rgb(92 ,183 ,74)\",\"rule\":\">\",\"value\":50},{\"color\":\"rgb(255, 0, 0)\",\"rule\":\">\",\"value\":1000}]},{\"optionKeys\":[\"standardOption\",\"colorSchame\"],\"value\":{\"color\":\"#0070cc\",\"schema\":\"threshold\"}},{\"optionKeys\":[\"columnOptions\",\"cellMode\"],\"value\":\"text\"},{\"optionKeys\":[\"columnOptions\",\"fontSize\"],\"value\":15}],\"queryName\":\"A\"},{\"name\":\"服务异常\",\"overrides\":[{\"optionKeys\":[\"thresholds\"],\"value\":[{\"color\":\"rgb(115, 191, 105)\",\"rule\":\">\",\"value\":0},{\"color\":\"rgb(244, 181, 36)\",\"rule\":\">\",\"value\":1},{\"color\":\"rgb(255, 0, 0)\",\"rule\":\">\",\"value\":30}]},{\"optionKeys\":[\"standardOption\",\"colorSchame\"],\"value\":{\"color\":\"#0070cc\",\"schema\":\"threshold\"}},{\"optionKeys\":[\"columnOptions\",\"cellMode\"],\"value\":\"text\"},{\"optionKeys\":[\"columnOptions\",\"fontSize\"],\"value\":15}],\"queryName\":\"A\"}],\"height\":6.4772725,\"queryOptionMap\":{\"A\":{}},\"showTitle\":true,\"standardOption\":{\"decimals\":2,\"format\":\"none\",\"unit\":\"none\"},\"tableOptions\":{\"pageSize\":20,\"rowHeight\":36,\"showGaugeTitle\":true,\"showHeader\":true,\"showMode\":\"pagination\",\"showTotal\":true,\"transparentBackground\":false},\"valueMappingOption\":[],\"version\":2,\"width\":5.08,\"xPos\":-0.05,\"yPos\":-0.056818184,\"zIndex\":10},\"action\":{}}]}\n";

}
